package com.urbansquall.ginger
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Matrix;

	internal class Frame
	{
		public var numFrames:int;
		public var bitmapData:Array;
		public var frameID:String;
		public var center:Number;
		
		public function Frame( a_numFrames:int, a_bitmapData:BitmapData, a_numRotations:int, a_frameID:String )
		{
			numFrames = a_numFrames;
			frameID = a_frameID;
			bitmapData = [];
			
			var tileWidth:int = a_bitmapData.width;
			var tileHeight:int = a_bitmapData.height;
			var tx:Number = ( tileWidth / 2 ) * Math.SQRT2;
			var ty:Number = ( tileHeight / 2 ) * Math.SQRT2;
			var maxTxy:Number = Math.max( tx, ty );
			center = maxTxy;
			var bdSize:Number = Math.ceil( Math.max( tileWidth, tileHeight ) * Math.SQRT2 );
			var mat:Matrix = new Matrix( 1, 0, 0, 1, maxTxy, maxTxy );
	 		var bd:BitmapData = new BitmapData( bdSize, bdSize, true, 0x00000000 );
			
			var container:Sprite = new Sprite();
 			var bmpHolder:Sprite = new Sprite();
 			var bmpData:BitmapData = new BitmapData( tileWidth, tileHeight, true, 0x00000000);
 			var bmp:Bitmap = new Bitmap( a_bitmapData, "auto", true );
 			bmp.x = -( tileWidth / 2 ); 
 			bmp.y = -( tileHeight / 2 ); 			
 			bmpHolder.addChild(bmp);
 			container.addChild(bmpHolder);
 			
 			var ri:int = 0;
 			while( ri < a_numRotations )
 			{
 				bd.fillRect( bd.rect, 0x00000000 );						
 				bd.draw( container, mat );
 				
 				bitmapData[ ri ] = bd.clone();
 				bmpHolder.rotation += 360 / a_numRotations;
 				
 				ri++;
 			}
 			
		}
	}
}
	